﻿<%@page import="com.pay.gopay.server.MD5"%>
<%@page import="com.jsp.payment.service.PaymentService"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.vo.Gateway"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;

	String version = request.getParameter("version");	//网关版本号
	String charset = request.getParameter("charset");	//字符集
	String language = request.getParameter("language");		//网关语言版本
	String signType = request.getParameter("signType");		//报文加密方式
	String tranCode = request.getParameter("tranCode");		//交易代码
	String merchantID = request.getParameter("merchantID");		//商户代码
	String merOrderNum = request.getParameter("merOrderNum");	//订单号
	String tranAmt = request.getParameter("tranAmt");			//交易金额
	String feeAmt = request.getParameter("feeAmt");				//商户提取佣金金额
	String frontMerUrl = request.getParameter("frontMerUrl");		//商户前台通知地址
	String backgroundMerUrl = request.getParameter("backgroundMerUrl");		//商户后台通知地址
	String tranDateTime = request.getParameter("tranDateTime");			//订单发起交易时间
	String tranIP = request.getParameter("tranIP");			//用户浏览器IP
	String respCode = request.getParameter("respCode");		//响应码
	String msgExt = request.getParameter("msgExt");			//响应结果附加信息
	String orderId = request.getParameter("orderId");		//国付宝内部订单号
	String gopayOutOrderId = request.getParameter("gopayOutOrderId");	//gopayOutOrderId
	String bankCode = request.getParameter("bankCode");			//bankCode
	String tranFinishTime = request.getParameter("tranFinishTime");		//tranFinishTime
	String merRemark1 =  request.getParameter("merRemark1");			//merRemark1
	String merRemark2 =  request.getParameter("merRemark2");			//merRemark2
	Gateway gateway = Gateway.dao.findById(18);
	String VerficationCode = gateway.getStr("gateway_key");		
	String signValueFromGopay = request.getParameter("signValue");		//signValue


	String md5Str = "version=[" + version + "]tranCode=[" + tranCode + "]merchantID=[" + merchantID + "]merOrderNum=[" + merOrderNum + "]tranAmt=[" + tranAmt + "]feeAmt=[" + feeAmt+ "]tranDateTime=[" + tranDateTime + "]frontMerUrl=[" + frontMerUrl + "]backgroundMerUrl=[" + backgroundMerUrl + "]orderId=[" + orderId + "]gopayOutOrderId=[" + gopayOutOrderId + "]tranIP=[" + tranIP + "]respCode=[" + respCode + "]gopayServerTime=[]VerficationCode=[" + VerficationCode + "]";
	System.out.println("md5Str=" + md5Str);
	MD5 md5 = new MD5();
	String MD5info = md5.getMD5ofStr(md5Str).toLowerCase();
	System.out.println("MD5info=" + MD5info);
	System.out.println("signValueFromGopay=" + signValueFromGopay);
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	if(MD5info.equals(signValueFromGopay)){
		if(respCode.equals("0000")){
			PaymentService.service.netcallback("", merOrderNum, "", sdf.format(new Date()), sdf.format(new Date()));
			response.sendRedirect(basePath+"/payment/showPayOk");
		}else{
			PaymentService.service.failure(merOrderNum, sdf.format(new Date()));
			response.sendRedirect(basePath+"/payment/showPayNo");
		}
	}else{
		out.println("交易签名被篡改!");
	}
%>